package org.libcsp.generic.api.response;

import lombok.*;

import java.util.Collection;
import java.util.Collections;

@Getter
@Setter
@ToString
@SuppressWarnings("unused")
public class Page<T extends GenericResponse> extends AbstractResponse{
    private Collection<T> records;
    private long total;

    private Page() {

    }
    private Page(Collection<T> records, long total) {
        this.records = safeCollection(records);
        this.total = total;
    }

    private Collection<T> safeCollection(Collection<T> records) {
        return records == null ? Collections.emptyList() : records;
    }

    public static <T extends GenericResponse> Page<T> of(Iterable<T> records,long total){
        return new Page<>((Collection<T>) records,total);
    }
    public static <T extends GenericResponse> Page<T> of(Collection<T> records,long total){
        return new Page<>(records,total);
    }
}
